﻿using System;
using System.Diagnostics;
using System.Net;

namespace SampleHttpServer
{
    public sealed class HttpHandler
    {
        public async void HandleHttpRequestEvent(HttpRequestEvent message)
        {
            HttpListenerContext context = message.Value;

            byte[] buffer = context.Request.ContentEncoding.GetBytes(string.Format("Timestamp {0}", DateTime.Now));
            await context.Response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
            context.Response.StatusCode = 200;

            try
            {
                context.Response.Close();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
            }
        }
    }
}